package com.xcf.util;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
/**
 * 批量转码
 * @author tanwei
 *
 */
public class TranscodUntil{
//	PageData map = null;
//	HttpServletRequest request;
	public static PageData Transcod(PageData pd){
//		this.request = request;
//		Map properties = request.getParameterMap();
//		Map returnMap = new HashMap(); 
		PageData pdq = new PageData();
		Iterator entries = pd.entrySet().iterator(); 
		PageData.Entry entry; 
		String name = "";  
		String value = "";  
		while (entries.hasNext()) {
			entry = (PageData.Entry) entries.next(); 
			name = (String) entry.getKey(); 
			Object valueObj;
			try {
				valueObj = URLDecoder.decode(entry.getValue().toString(), "utf-8");
				if(null == valueObj){ 
					value = ""; 
				}else if(valueObj instanceof String[]){ 
					String[] values = (String[])valueObj;
					for(int i=0;i<values.length;i++){ 
						 value = values[i] + ",";
					}
					value = value.substring(0, value.length()-1); 
				}else{
					value = valueObj.toString(); 
				}
				pdq.put(name, value);
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
			
			 
		}
		return  pdq;
	}
}
